﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Entity.DbEntity;
using Tools;
using CommandService;
using System.Data;
using Entity.ViewEntity;
using System.Reflection;
using SysFramework;
using System.Security.AccessControl;
using log4net;
using Entity.FrameEntity;
using Microsoft.Data.SqlClient;
using System.Reflection.Emit;
using Entity.ViewEntity.AppView;
using System.Collections;
using System.Diagnostics;
using Microsoft.Data.SqlClient.DataClassification;
using static System.Runtime.CompilerServices.RuntimeHelpers;

namespace BLL
{
    public class AppBLL : PubMethod
    {
        Commands cmd;

        ReturnResult rsl;
        PubMethod pubMethod;
        DataTable dt;
        StringBuilder sb = new StringBuilder();
        BarBLL barBLL;
        ServiceBLL serviceBLL = new ServiceBLL();
        OutBaseHelper outBase;
        ILog _log;
        OperateModel oper;
        DbTempScanData scan;
        AppMobilesInfo appInfo;

        //SystemBLL sysBLL;
        //MsgResult Msg;
        //TokenInfo TokenInfo;
        //ServiceRecord ServiceRecord;

        //DbProductBar barInfor;

        //SqlParameter sqlParameter;
        //BaseCommon baseCommon;
        //AppMobilesInfo appInfo;
        //AppUpdateInfo appUpdateInfo;

        public AppBLL()
        {
            //sql访问类
            cmd = new Commands();
            outBase = new OutBaseHelper();
            pubMethod = new PubMethod();
            barBLL = new BarBLL();
            _log = LogManager.GetLogger(this.GetType().Name);
            //sql操作类
            oper = new OperateModel();

            ////token存储类
            //TokenInfo = new TokenInfo();
            ////移动设备调用接口记录
            //ServiceRecord = new ServiceRecord();
            //baseCommon = new BaseCommon();
        }

        /// <summary>
        /// 获取账套
        /// </summary>
        /// <returns></returns>
        public ReturnResult getAccount(string str)
        {
            #region 获取账套
            rsl = new ReturnResult();
            try
            {
                string acount = string.Empty;
                if (string.IsNullOrWhiteSpace(str))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                #region 解密方法
                var jsonStr = Encryption.DesDecrypt(str);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                #endregion
                //rsl = sysBLL.CustomBaseInfo();
                StringBuilder sb = new StringBuilder();
                sb.Append("select * from V_CustomBaseInfo");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count > 0)
                {
                    var data = new List<Dictionary<string, string>>();
                    if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                    {
                        foreach (DataRow item in table.Rows)
                        {
                            var obj = new Dictionary<string, string>();
                            obj["value"] = item["DbCode"].ToString();
                            obj["text"] = item["customName"].ToString();
                            data.Add(obj);
                        }
                    }
                    else
                    {
                        data = cmd.TableToDictionary(table);
                    }
                    rsl.Data = data;
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "没有数据";
                }
                _log.Info("getAccount:方法" + JsonConvert.SerializeObject(rsl));
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }

            return rsl;
            #endregion
        }

        /// <summary>
        /// 登录验证
        /// </summary>
        /// <returns></returns>
        public ReturnResult login(String jsonStr)
        {
            #region 登录验证
            try
            {
                rsl = new ReturnResult();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数丢失";
                    return rsl;
                }
                #region 解密方法
                jsonStr = Encryption.DesDecrypt(jsonStr);

                #endregion
                _log.Info("login方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                if (string.IsNullOrWhiteSpace(json["userCode"].ToString()))
                {
                    rsl.Result = false;
                    rsl.Message = "登录账号不允许为空";
                    return rsl;
                }
                if (string.IsNullOrWhiteSpace(json["userPwd"].ToString()))
                {
                    rsl.Result = false;
                    rsl.Message = "登录密码不允许为空";
                    return rsl;
                }

                DbUser user = new DbUser();
                user.userCode = json["userCode"].ToString().Trim();
                user.userPwd = Tools.Encryption.MD5Encode(json["userPwd"].ToString().Trim());
                user.status = "Y";//启用状态
                var list = cmd.GetDataByObject<LoginUser>(user);
                if (list.Count > 0)
                {
                    list[0].baseCode = json["baseCode"].ToString();
                    rsl.Data = list[0];
                    rsl.Result = true;
                }
                else
                {
                    rsl.Message = "账号或密码错误";
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
            #endregion
        }

        /// <summary>
        /// 获取移动端功能菜单（H5端接口）
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult GetMenuList(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                oper = new OperateModel();
                StringBuilder sb = new StringBuilder();
                var parentTable = new DataTable();
                var childTable = new DataTable();
                Dictionary<string, object> childDic = new Dictionary<string, object>();
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                List<List<Dictionary<string, string>>> debugList = new List<List<Dictionary<string, string>>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                //DbProductCheckMain checkMain = new DbProductCheckMain();
                List<SqlParameter> sqlList = new List<SqlParameter>();
                #region 获取功能菜单
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                sb.Append(" select *,convert(int,orderNum) orderNumi from sys_MenuInfo ");
                sb.Append(" where  mType='APP' and isdel=0 and status='Y'");
                parentTable = cmd.GetDataTable(sb.ToString());
                if (parentTable.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取菜单数据";
                    return rsl;
                }

                #region 获取用户
                var powerDt = new DataTable();
                var isAdmin = false;
                if (json.Property("userCode") != null && !string.IsNullOrWhiteSpace(json["userCode"].ToString()))
                {
                    sb.Clear();
                    sb.Append("select * from sys_users_info where 1=1 and isDel<>1 ");
                    sb.Append(" and status='Y' and userCode='" + json["userCode"].ToString() + "' ");
                    var dt = cmd.GetDataTable(sb.ToString());
                    if (dt == null || dt.Rows.Count < 1)
                    {
                        rsl.Result = false;
                        rsl.Message = "没有获取登陆人信息";
                        return rsl;
                    }
                    if (dt.Rows[0]["isAdmin"].ToString().Equals("1"))
                    {
                        isAdmin = true;
                    }
                    else
                    {
                        var select = dt.Select("baseCode='" + json["baseCode"].ToString() + "'");
                        if (select == null || select.Length < 1)
                        {
                            rsl.Result = false;
                            rsl.Message = "没有获取登陆人信息";
                            return rsl;
                        }
                        var powerRole = select[0]["powerRole"].ToString();
                        if (!string.IsNullOrWhiteSpace(powerRole))
                        {
                            sb.Clear();
                            sb.Append("select gp.* ");
                            sb.Append(" from sys_powerConfig_groups g ");
                            sb.Append("inner join sys_powerConfig_groupPower gp on g.groupCode = gp.groupCode ");
                            sb.Append(" where 1=1 and g.isDel<>1 and status='Y' ");
                            sb.Append(" and g.groupCode='" + powerRole + "'");
                            powerDt = cmd.GetDataTable(sb.ToString());
                            if (powerDt == null || powerDt.Rows.Count < 1)
                            {
                                rsl.Result = false;
                                rsl.Message = "无权限";
                                return rsl;
                            }
                        }
                        else
                        {
                            rsl.Result = false;
                            rsl.Message = "无权限";
                            return rsl;
                        }
                    }
                }
                else
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取登陆人信息";
                    return rsl;
                }
                #endregion
                var selectParent = parentTable.Select("menuLevel='1'");
                var parentList = new List<Dictionary<string, object>>();
                if (selectParent != null && selectParent.Length > 0)
                {
                    var dt = selectParent.CopyToDataTable<DataRow>();
                    var dv = dt.DefaultView;
                    dv.Sort = "orderNumi asc";
                    dt = dv.ToTable();
                    foreach (DataRow item in dt.Rows)
                    {
                        var obj = new Dictionary<string, object>();
                        obj["title"] = item["menuName"].ToString();
                        obj["code"] = item["menuCode"].ToString();
                        obj["name"] = item["menuName"].ToString();
                        obj["menuCount"] = 4;
                        obj["pathUrl"] = item["menuPath"].ToString();
                        obj["icon"] = item["menuIcon"].ToString();
                        if (!string.IsNullOrWhiteSpace(item["memo"].ToString()))
                        {
                            var memoDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(item["memo"].ToString());
                            obj["color"] = "#ffffff";
                            obj["size"] = "30";
                            obj["imageColor"] = "#ba251e, #ba4805";
                            obj["pageType"] = "01";
                            if (memoDic.ContainsKey("color") && !string.IsNullOrWhiteSpace(memoDic["color"].ToString()))
                            {
                                obj["color"] = memoDic["color"];
                            }
                            if (memoDic.ContainsKey("imageColor") && !string.IsNullOrWhiteSpace(memoDic["imageColor"].ToString()))
                            {
                                obj["imageColor"] = memoDic["imageColor"].ToString();
                            }
                            if (memoDic.ContainsKey("size") && !string.IsNullOrWhiteSpace(memoDic["size"].ToString()))
                            {
                                obj["size"] = memoDic["size"].ToString();
                            }
                            if (memoDic.ContainsKey("pageType") && !string.IsNullOrWhiteSpace(memoDic["pageType"].ToString()))
                            {
                                obj["pageType"] = memoDic["pageType"].ToString();
                            }
                        }
                        var menuList = new List<Dictionary<string, object>>();
                        var selectChildren = parentTable.Select("parentMenu='" + item["menuCode"].ToString() + "'");
                        if (selectChildren != null && selectChildren.Length > 0)
                        {
                            var cdt = selectChildren.CopyToDataTable<DataRow>();
                            var cdv = cdt.DefaultView;
                            cdv.Sort = "orderNumi asc";
                            cdt = cdv.ToTable();
                            foreach (DataRow ci in cdt.Rows)
                            {
                                this.createMenu(parentTable, ci, ref menuList, isAdmin, powerDt);
                            }
                        }
                        obj["list"] = menuList;
                        if (menuList.Count > 0)
                        {
                            parentList.Add(obj);
                        }
                    }
                }
                //var parentList = cmd.TableToDictionary(parentTable);
                dic.Add("parentList", parentList);
                rsl.Result = true;
                rsl.Data = dic;
                #endregion
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }

        /// <summary>
        /// 创建菜单列表
        /// </summary>
        /// <param name="parentTable"></param>
        /// <param name="item"></param>
        /// <param name="menuList"></param>
        /// <param name="isAdmin"></param>
        /// <param name="powerDt"></param>
        private void createMenu(DataTable parentTable, DataRow item, ref List<Dictionary<string, object>> menuList, Boolean isAdmin = false, DataTable powerDt = null)
        {
            var obj = new Dictionary<string, object>();
            obj["title"] = item["menuName"].ToString();
            obj["code"] = item["menuCode"].ToString();
            obj["name"] = item["menuName"].ToString();
            obj["menuCount"] = 4;
            obj["pathUrl"] = item["menuPath"].ToString();
            obj["icon"] = item["menuIcon"].ToString();
            if (!string.IsNullOrWhiteSpace(item["memo"].ToString()))
            {
                var memoDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(item["memo"].ToString());
                obj["color"] = "#ffffff";
                obj["size"] = "30";
                obj["imageColor"] = "#ba251e, #ba4805";
                obj["pageType"] = "01";
                if (memoDic.ContainsKey("color") && !string.IsNullOrWhiteSpace(memoDic["color"].ToString()))
                {
                    obj["color"] = memoDic["color"];
                }
                if (memoDic.ContainsKey("imageColor") && !string.IsNullOrWhiteSpace(memoDic["imageColor"].ToString()))
                {
                    obj["imageColor"] = memoDic["imageColor"].ToString();
                }
                if (memoDic.ContainsKey("size") && !string.IsNullOrWhiteSpace(memoDic["size"].ToString()))
                {
                    obj["size"] = memoDic["size"].ToString();
                }
                if (memoDic.ContainsKey("pageType") && !string.IsNullOrWhiteSpace(memoDic["pageType"].ToString()))
                {
                    obj["pageType"] = memoDic["pageType"].ToString();
                }
            }
            //var menuList = new List<Dictionary<string, object>>();
            var pmenuList = new List<Dictionary<string, object>>();
            //获取子菜单
            var selectChildren = parentTable.Select("parentMenu='" + item["menuCode"].ToString() + "'");
            if (selectChildren != null && selectChildren.Length > 0)
            {
                var cdt = selectChildren.CopyToDataTable<DataRow>();
                var cdv = cdt.DefaultView;
                cdv.Sort = "orderNumi asc";
                cdt = cdv.ToTable();
                foreach (DataRow ci in cdt.Rows)
                {
                    this.createMenu(parentTable, ci, ref pmenuList, isAdmin, powerDt);
                }
            }
            else
            {
                #region 判断是否有该菜单权限
                if (!isAdmin && powerDt != null && powerDt.Rows.Count > 0)
                {
                    var powerSelect = powerDt.Select("menuCode='" + item["menuCode"].ToString() + "'");
                    if (powerSelect != null && powerSelect.Length > 0)
                    {
                        if (string.IsNullOrWhiteSpace(powerSelect[0]["operates"].ToString()))
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                #endregion
            }
            obj["list"] = pmenuList;
            menuList.Add(obj);
        }

        /// <summary>
        ///获取出入库默认仓库信息
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public ReturnResult getInOutWareStyle(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取收发类型
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                StringBuilder sb = new StringBuilder();
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  and parCode like '%Ware_Style'");
                var wareStyle = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(wareStyle);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 获取仓库信息
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getWareHouse(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                #region 解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                #endregion
                _log.Info("getWareHouse方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var inOutTypeFalse = new[] { "piyb", "poyb" };  //"pobg","pibg",
                StringBuilder sb = new StringBuilder();
                if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                {
                    if (!inOutTypeFalse.Contains(json["inOutType"].ToString()))
                    {
                        sb.Clear();
                        sb.Append("select houseCode code,houseName name from fun_WareHouse_Info");
                        sb.Append(" where isdel=0 and status='open'");
                        if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                        {
                            sb.Append(" and baseCode = '" + json["baseCode"] + "'");
                        }
                    }

                    var table = cmd.GetDataTable(sb.ToString());
                    var data = new List<Dictionary<string, string>>();
                    if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                    {
                        if (table.Rows.Count > 0)
                        {
                            foreach (DataRow item in table.Rows)
                            {
                                var obj = new Dictionary<string, string>();
                                obj["value"] = item["code"].ToString();
                                obj["text"] = item["name"].ToString() + "(" + item["code"].ToString() + ")";
                                data.Add(obj);
                            }
                        }
                    }
                    else
                    {
                        data = cmd.TableToDictionary(table);
                    }
                    rsl.Data = data;
                    rsl.Result = true;

                }

            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = "发生仓库：" + ex.Message;
                return rsl;
            }
            return rsl;
        }

        /// <summary>
        ///获取出入库默认部门信息
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public ReturnResult getInOutDeptStyle(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取收发类型
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                StringBuilder sb = new StringBuilder();
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  and parCode like '%Dept_Style'");
                var wareStyle = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(wareStyle);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 获取部门信息
        /// </summary>
        /// <param name="josnStr"></param>
        /// <returns></returns>
        public ReturnResult getDepartment(string jsonStr)
        {
            try
            {
                rsl = new ReturnResult();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                #region 解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                #endregion
                _log.Info("getDepartment方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb = new StringBuilder();
                //sb.Append("select deptCode code,deptName name from sys_DepartMent_Info where status='Y'");
                sb.Append("select trCode code,trName name from fun_CommonTree_info where isdel = 0 and trType = 'dept'  and parentCode is not null and parentCode!='' ");
                if (!string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    sb.Append(" and baseCode = '" + json["baseCode"] + "'");
                }
                var table = cmd.GetDataTable(sb.ToString());
                var data = new List<Dictionary<string, string>>();
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (table.Rows.Count > 0)
                    {
                        foreach (DataRow item in table.Rows)
                        {
                            var obj = new Dictionary<string, string>();
                            obj["value"] = item["code"].ToString();
                            obj["text"] = item["name"].ToString();
                            data.Add(obj);
                        }
                    }
                }
                else
                {
                    data = cmd.TableToDictionary(table);
                }
                rsl.Data = data;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = "发生部门：" + ex.Message;
                return rsl;
            }
            return rsl;
        }

        /// <summary>
        ///获取收发类型与出入库的对应关系
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public ReturnResult getInOutRdStyle(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取收发类型
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                StringBuilder sb = new StringBuilder();
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  and parCode like '%Rd_Style'");
                var rdStyle = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(rdStyle);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        ///获取收发类型
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public ReturnResult getRdStyle(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取收发类型
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);

                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                if (json.Property("baseCode") == null || string.IsNullOrWhiteSpace(json["baseCode"].ToString()))
                {
                    rsl.Result = false;
                    rsl.Message = "没有获取账套号";
                    return rsl;
                }
                StringBuilder sb = new StringBuilder();
                if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                {
                    sb.Append("select cRdCode AS code, cRdName AS name,bRdFlag from Rd_Style");
                    sb.Append(" where bRdEnd = 1  ");
                    sb.Append(" and bRdFlag='" + json["dFlag"].ToString() + "'");
                }
                var rdStyle = outBase.getData(sb.ToString(), json["baseCode"].ToString());
                var data = new List<Dictionary<string, string>>();
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (rdStyle.Rows.Count > 0)
                    {
                        foreach (DataRow item in rdStyle.Rows)
                        {
                            var obj = new Dictionary<string, string>();
                            obj["value"] = item["code"].ToString();
                            obj["text"] = item["name"].ToString() + "(" + item["code"].ToString() + ")";
                            data.Add(obj);
                        }

                        //材料出库时，新增个特殊的出库类型，选择此类型时做调拨单
                        if (json["inOutType"].ToString() == "pom")
                        {
                            var spObj = new Dictionary<string, string>();
                            spObj["value"] = "999";
                            spObj["text"] = "其他材料出库(999)";
                            data.Add(spObj);
                        }
                        
                    }
                }
                else
                {
                    data = cmd.TableToDictionary(rdStyle);
                }
                rsl.Data = data;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = "发生类型：" + ex.Message;
                return rsl;
            }
            #endregion
            return rsl;

        }

        /// <summary>
        ///获取版辊出入库类型与出入库的对应关系
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public ReturnResult getbgIoStyle(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取版辊出入库类型
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                StringBuilder sb = new StringBuilder();
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  and parCode like '%Bg_Style'");
                var rdStyle = cmd.GetDataTable(sb.ToString());
                rsl.Data = cmd.TableToDictionary(rdStyle);
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        ///获取版辊出入库类型信息
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public ReturnResult GetbgIoType(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取版辊出入库类型信息
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对穿入数据进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);

                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                StringBuilder sb = new StringBuilder();
                if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                {

                    sb.Append("select code,name,extendFile from sys_dictionaries_info where types='bgiot' ");
                    if (json["dFlag"].ToString() == "0")
                    {
                        sb.Append(" and extendFile='pot'");
                    }
                    else
                    {
                        sb.Append(" and extendFile='pit'");
                    }

                }
                var rdStyle = cmd.GetDataTable(sb.ToString());
                var data = new List<Dictionary<string, string>>();
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (rdStyle != null && rdStyle.Rows.Count > 0)
                    {
                        foreach (DataRow item in rdStyle.Rows)
                        {
                            var obj = new Dictionary<string, string>();
                            obj["value"] = item["code"].ToString();
                            obj["text"] = item["name"].ToString() + "(" + item["code"].ToString() + ")";
                            data.Add(obj);
                        }
                    }
                }
                else
                {
                    data = cmd.TableToDictionary(rdStyle);
                }
                rsl.Data = data;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = "版辊出入库类型：" + ex.Message;
                return rsl;
            }
            #endregion
            return rsl;

        }

        /// <summary>
        /// 获取临时表中的扫描单号数据
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getTempCode(string jsonStr)
        {
            rsl = new ReturnResult();
            sb = new StringBuilder();
            #region 获取临时表中的扫描数据
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Append("select parCode AS code, parName AS name,parValue as value from sys_parameters_info");
                sb.Append(" where isDel=0 and enable='open'  ");
                if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                {
                    sb.Append(" and parCode='" + json["inOutType"].ToString() + "_Rd_Style" + "'");
                }

                var rdStyle = cmd.GetDataTable(sb.ToString());
                sb.Clear();
                sb.Append(" select tmp.*,c.cName AS customName ");
                sb.Append(" FROM  dbo.bar_TempScanData_info ");
                sb.Append(" AS  tmp LEFT  JOIN ");
                sb.Append(" dbo.fun_CommonData_Info AS c ON tmp.customCode = c.cCode and c.cType='Cu' ");
                sb.Append(" and c.isDel=0 and c.status='Y' and c.specFile='" + json["baseCode"].ToString() + "'");
                sb.Append(" where 1=1 ");

                if (json.Property("operateType") != null && !string.IsNullOrWhiteSpace(json["operateType"].ToString()))
                {
                    sb.Append(" and operateType ='" + json["operateType"].ToString() + "' ");
                }
                if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                {
                    sb.Append(" and  (inOutType ='" + json["inOutType"].ToString() + "'  or  operateCode ='" + json["inOutType"].ToString() + "' ) ");
                }
                var tempDt = cmd.GetDataTable(sb.ToString());
                var tempCodes = new Dictionary<string, string>();
                var dt = tempDt.Clone();
                foreach (DataRow row in tempDt.Rows)
                {
                    if (!tempCodes.Keys.Contains(row["tempCode"].ToString().Trim()))
                    {
                        var rowNum = 0;
                        var selectRow = tempDt.Select("tempCode='" + row["tempCode"].ToString().Trim() + "'");
                        if (selectRow != null && selectRow.Length > 0)
                        {
                            rowNum = selectRow.Length;
                        }
                        tempCodes.Add(row["tempCode"].ToString().Trim(), rowNum.ToString());
                        dt.Rows.Add(row.ItemArray);
                    }
                }
                var data = new List<Dictionary<string, string>>();
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (dt.Rows.Count > 0)
                    {
                        dt.Columns.Add("value");
                        dt.Columns.Add("text");
                        dt.Columns.Add("barNumber");
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            var item = dt.Rows[i];
                            item["value"] = item["tempCode"].ToString();
                            item["text"] = item["tempCode"].ToString();
                            item["barNumber"] = tempCodes[item["tempCode"].ToString()].ToString();
                        }
                        data = cmd.TableToDictionary(dt);
                    }
                }
                else
                {
                    data = cmd.TableToDictionary(dt);
                }
                rsl.Data = data;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            #endregion

            return rsl;
        }

        /// <summary>
        /// 获取计划单列表
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult GetPlanList(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取计划信息
            try
            {
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                List<int> widthList = new List<int>();//列宽度列表
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                _log.Info("GetPlanList：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                //cDefine1实际客户(客户名称在U8是唯一的)，cDefine2实际业务员
                sb.Append(" select top 100 * from V_PI_ProductPlan_info where isdel=0 and status!='ps-finish' and status!='ps-pg-set' ");  //已经派工的 未完成的
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (json.Property("plCode") != null && !string.IsNullOrWhiteSpace(json["plCode"].ToString()))
                    {
                        sb.Append(" and plCode like '%" + json["plCode"].ToString().Trim() + "%' ");
                    }
                    if (json.Property("cuName") != null && !string.IsNullOrWhiteSpace(json["cuName"].ToString()))
                    {
                        sb.Append(" and cuName like '%" + json["cuName"].ToString().Trim() + "%' ");
                    }
                    if (json.Property("proName") != null && !string.IsNullOrWhiteSpace(json["proName"].ToString()))
                    {
                        sb.Append(" and proName like '%" + json["proName"].ToString().Trim() + "%' ");
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(json["conditions"].ToString()))
                    {
                        sb.Append(" and (plCode like '%" + json["conditions"] + "%' ");//计划单号
                        sb.Append(" or cuName like '% " + json["conditions"].ToString() + "%'");//客户名称
                        sb.Append(" or proName like '% " + json["conditions"].ToString() + "%')");//存货名称
                    }
                }
                sb.Append(" order by createtime desc ");
                var table = cmd.GetDataTable(sb.ToString());
                if (table.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有数据";
                    return rsl;
                }

                var List = cmd.TableToDictionary(table);

                string byCode = "";
                foreach (var s in List)
                {
                    byCode = "";
                    sb.Clear();
                    sb.Append("select distinct byCode from fun_BanYang_list where byBarCode in (select materialCode from bom_ProductionBom_sub where bomCode='" + s["bomCode"].ToString() + "' and materialType='bangun')");
                    table = cmd.GetDataTable(sb.ToString());
                    
                    foreach (DataRow dr in table.Rows)
                    {
                        byCode +=dr["byCode"].ToString()+ ",";
                    }

                    s["byCode"]=byCode.TrimEnd(',');
                }

                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    #region 构建表头数据
                    var headData = new List<object>();
                    var head = new Dictionary<string, string>();
                    var obj = new { field = "plCode", name = "计划编码", width = "150" };
                    headData.Add(obj);
                    obj = new { field = "cuName", name = "客户名称", width = "150" };
                    headData.Add(obj);
                    obj = new { field = "proName", name = "存货名称", width = "150" };
                    headData.Add(obj);
                    if (json["inOutType"].ToString() != "db")  //目前是材料出库和调拨时会选计划，  材料出库时显示版
                    {
                        obj = new { field = "byCode", name = "版号", width = "100" };
                        headData.Add(obj);
                    }
                    #endregion
                    dic.Add("headData", headData);
                    dic.Add("list", List);
                }
                else
                {
                    Dictionary<string, string> temdic = new Dictionary<string, string>();
                    var widths = new int[] { 150, 150, 150, 150 };
                    widthList = widths.ToList();
                    temdic.Add("plCode", "计划编码");
                    temdic.Add("cuName", "客户名称");//实际客户
                    temdic.Add("proName", "存货名称");//存货名称
                    //temdic.Add("createtime", "创建时间");
                    List.Insert(0, temdic);
                    dic.Add("widthList", widthList);
                    dic.Add("list", List);
                }

                rsl.Data = dic;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 扫描编码(临时码)生成方法
        /// </summary>   
        /// <returns></returns>
        public ReturnResult getScanCode(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取扫描单号
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对字符串进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                _log.Info("getScanCode方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                if (string.IsNullOrWhiteSpace(json["types"].ToString()) || string.IsNullOrWhiteSpace(json["memo"].ToString()))
                {
                    rsl.Result = false;
                    rsl.Message = "条码类别参数值不能为空";
                    return rsl;
                }
                rsl.Data = this.CreateCodeInfo(json["types"].ToString(), json["memo"].ToString(), "3", 1);//获取扫描单号
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 保存出入库扫描的条码数据到临时表
        /// </summary>
        /// <param name="jsonStr"></param>
        public ReturnResult addScanRecord(string jsonStr)
        {
            rsl = new ReturnResult();
            DataTable planList = new DataTable();
            List<OperateModel> operList = new List<OperateModel>();
            #region 保存扫描单号数据
            try
            {
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //对字符串进行解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                
                var obj = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var inOutTypesFalse = new[] { "piyb", "poyb", "pibg" };//虚拟出入库类型   "pobg","pibg",

                if (obj.Property("barcodeNumber") != null && !string.IsNullOrWhiteSpace(obj["barcodeNumber"].ToString()))
                {
                    var tempBarCode = obj["barCode"].ToString();
                    var barCode = string.Empty;//条码编码
                    var number = string.Empty;//重量
                    for (int i = 0; i < Convert.ToInt32(obj["barcodeNumber"].ToString()); i++)
                    {
                        var str = "";
                        barCode = tempBarCode;
                        Dictionary<string, string> dic = new Dictionary<string, string>();
                        dic.Add("inOutType", obj["inOutType"].ToString());
                        dic.Add("baseCode", obj["baseCode"].ToString());
                        //判断是否为正确条码
                        rsl = serviceBLL.CheckBarCode(barCode, dic);
                        if (rsl.Result)
                        {
                            var barDataList = rsl.Data;
                            //判断是否为已扫描条码（同一个临时码 重复扫描）
                            rsl = serviceBLL.CheckRepeatTempBar(jsonStr);
                            if (Convert.ToInt32(rsl.Data) == 1 && rsl.Result)
                            {
                                rsl.Message = "该标签已扫描";
                                rsl.Result = false;
                                return rsl;
                            }
                            rsl.Result = false;

                            #region 各操作 条码状态 验证
                            List<Dictionary<string, string>> list = (List<Dictionary<string, string>>)barDataList;
                            foreach (Dictionary<string, string> item in list)
                            {
                                #region 判断条码是否作废  和   是否被其他临时码扫描
                                if (!inOutTypesFalse.Contains(obj["inOutType"].ToString()))
                                {
                                    number = item["number"].ToString();
                                    if (item["barStatus"].ToString().Equals("bar-drop"))
                                    {
                                        rsl.Result = false;
                                        rsl.Message = "该标签已作废";
                                        return rsl;
                                    }
                                }
                                sb.Clear();
                                sb.Append("select sc.*,dic.name inOutTypeName from bar_TempScanData_info sc ");
                                sb.Append(" inner join sys_dictionaries_info dic on sc.inOutType=dic.code ");
                                sb.Append(" where 1=1 and tempCode<>'" + obj["tempCode"].ToString() + "' ");
                                sb.Append(" and barCode='" + barCode + "'");
                                var scDt = cmd.GetDataTable(sb.ToString());
                                if (scDt != null && scDt.Rows.Count > 0)
                                {
                                    rsl.Result = false;
                                    rsl.Message = string.Format("该标签已被扫描，扫描单据号：{0}；扫描人：{1}；操作类型：{2}", scDt.Rows[0]["tempCode"].ToString(), scDt.Rows[0]["createuser"].ToString(), scDt.Rows[0]["inOutTypeName"].ToString());
                                    return rsl;
                                }

                                #endregion

                                #region 扫码入库
                                if (obj["operateType"].ToString().Equals("01"))
                                {
                                    #region 判断条码的状态
                                    //虚拟其它入库不判定状态
                                    if (obj["isBlue"].ToString().Equals("1") && !inOutTypesFalse.Contains(obj["inOutType"].ToString()))
                                    {

                                        //if (obj["inOutType"].ToString().Equals("pio"))  //其他入
                                        //{
                                        //    if (!item["barStatus"].Equals("need-back"))
                                        //    {
                                        //        rsl.Message = "条码为" + getBarStatus(item["barStatus"].ToString()) + "状态不是待归还状态";
                                        //        rsl.Result = false;
                                        //        return rsl;
                                        //    }
                                        //}
                                        //else
                                        //{
                                        if (!item["barStatus"].Equals("need-in") && !item["barStatus"].Equals("bar-used"))
                                        {
                                            rsl.Message = "标签为" + getBarStatus(item["barStatus"].ToString()) + "状态不是待入库状态";
                                            rsl.Result = false;
                                            return rsl;
                                        }
                                        //}
                                    }
                                    else
                                    {
                                        if (obj["inOutType"].ToString() == "pibg")
                                        {
                                            var work_sql = "select parValue from sys_parameters_info where parCode = 'pibg_Ware_Style' ";
                                            var wt = cmd.GetDataTable(work_sql);   //获取版库编码
                                            var workCode = "004";
                                            if (wt.Rows.Count > 0)
                                                workCode = wt.Rows[0]["parValue"].ToString();

                                            if (item["wareHouse"].ToString() == workCode)
                                            {
                                                rsl.Result = false;
                                                rsl.Message = string.Format("此标签已在版库，禁止重复入库:{0}", barCode);
                                                return rsl;
                                            }
                                        }
                                        else
                                        {
                                            if (!item["barStatus"].Equals("need-out"))
                                            {
                                                rsl.Message = "标签为" + getBarStatus(item["barStatus"].ToString()) + "状态不是待出库状态禁止红单入库";
                                                rsl.Result = false;
                                                return rsl;
                                            }
                                        }
                                        
                                    }
                                    #endregion                                  
                                }
                                #endregion

                                #region 扫码出库
                                if (obj["operateType"].ToString().Equals("02"))
                                {
                                    #region 判断条码的状态
                                    //虚拟其它出库不判定状态
                                    if (obj["isBlue"].ToString().Equals("1") && !inOutTypesFalse.Contains(obj["inOutType"].ToString()))
                                    {
                                        //材料出库的时候生产使用状态和待出库状态都可以扫码
                                        //if (!obj["inOutType"].ToString().Equals("pom") && !item["barStatus"].Equals("need-out"))
                                        //{
                                        //    rsl.Message = "条码为" + getBarStatus(item["barStatus"].ToString()) + "状态，不可出库";
                                        //    rsl.Result = false;
                                        //    return rsl;
                                        //}

                                        if (!item["barStatus"].Equals("need-out"))
                                        {
                                            rsl.Message = "标签为" + getBarStatus(item["barStatus"].ToString()) + "状态，不可出库";
                                            rsl.Result = false;
                                            return rsl;
                                        }

                                        #region 出库时判断是否和条码所在的仓库相同
                                        if (string.IsNullOrWhiteSpace(item["wareHouse"].ToString()))
                                        {
                                            rsl.Message = "扫描的标签没有仓库信息，请确定是否入库";
                                            rsl.Result = false;
                                            return rsl;
                                        }
                                        if (!obj["wareHouse"].ToString().Equals(item["wareHouse"].ToString()))
                                        {
                                            rsl.Message = "选择的发生仓库不存在扫描的标签信息";
                                            rsl.Result = false;
                                            return rsl;
                                        }
                                        //if (isWarePosition(item["wareHouse"].ToString(), obj["baseCode"].ToString()) && string.IsNullOrWhiteSpace(item["warePosition"].ToString()))
                                        //{
                                        //    rsl.Message = "选择的发生仓库有货位管理，扫描的条码上必须有货位";
                                        //    rsl.Result = false;
                                        //    return rsl;
                                        //}
                                        //if (!string.IsNullOrWhiteSpace(item["warePosition"].ToString()) && (!obj["goodsPosition"].ToString().Equals(item["warePosition"].ToString())))
                                        //{
                                        //    rsl.Message = "选择的发生货位不存在扫描的条码信息";
                                        //    rsl.Result = false;
                                        //    return rsl;
                                        //}
                                        #endregion
                                    }
                                    else
                                    {
                                        if (!item["barStatus"].Equals("bar-finish"))
                                        {
                                            rsl.Message = "标签为" + getBarStatus(item["barStatus"].ToString()) + "状态不是完成状态禁止红单出库";
                                            rsl.Result = false;
                                            return rsl;
                                        }
                                    }
                                    #endregion


                                    //销售出库
                                    if (obj["inOutType"].ToString().Equals("pos"))
                                    {
                                        #region 检测选择的未审核发货单中存货是否和扫描的相同
                                        var orderCode = obj["outOrderCode"].ToString();
                                        if (orderCode.IndexOf('-') > 0)
                                        {
                                            orderCode = obj["outOrderCode"].ToString().Split('-')[0];
                                        }
                                        sb.Clear();
                                        sb.Append("select  main.cDLCode,main.cDepCode,main.cCusCode,main.cCusName,main.dDate,   ");//填写U8销售订单信息
                                        sb.Append(" mains.cInvCode,mains.cFree1,cFree2,cFree3,cFree4,cDefine22,cDefine23,mains.iQuantity  ");
                                        sb.Append(" from DispatchList main ");
                                        sb.Append(" inner join DispatchLists mains on main.DLID = mains.DLID  ");
                                        sb.Append("  where isnull(main.cVerifier,'') <>'' and isnull(main.dverifydate,'') <>''  ");
                                        sb.Append("  and main.cDLCode='" + orderCode + "' ");
                                        planList = outBase.getData(sb.ToString(), obj["baseCode"].ToString());
                                        if (planList.Rows.Count > 0)
                                        {
                                            var comNum = DateTime.Compare(Convert.ToDateTime(planList.Rows[0]["dDate"].ToString()), Convert.ToDateTime(obj["happenDate"].ToString()));
                                            if (comNum > 0)
                                            {
                                                rsl.Result = false;
                                                rsl.Message = string.Format("出库日期小于发货单日期，发货单：{0}，出库单：{1}", planList.Rows[0]["dDate"].ToString(), obj["happenDate"].ToString());
                                                return rsl;
                                            }


                                            if (!string.IsNullOrWhiteSpace(item["proCode"].ToString()))
                                            {
                                                sb.Clear();
                                                sb.Append("cInvCode='" + item["proCode"].ToString().Trim() + "' ");

                                                //判断属性和存货同时相同的数据
                                                var length = planList.Select(sb.ToString());
                                                if (length.Length <= 0)
                                                {
                                                    rsl.Result = false;
                                                    rsl.Message = "该发货单中没有你出库的存货信息";
                                                    return rsl;
                                                }
                                                else
                                                {
                                                    if (obj.Property("isContinue") != null && !Convert.ToBoolean(obj["isContinue"].ToString()))
                                                    {
                                                        var selectRow = length[0];
                                                        var iQuantity = Convert.ToDecimal(selectRow["iQuantity"].ToString());
                                                        #region 获取该临时码中扫描的条码个数
                                                        sb.Clear();
                                                        sb.Append("select bars.proCode,isnull(sum(CONVERT(decimal(18,2),bars.number)),0) number  from  bar_TempScanData_info tem ");
                                                        sb.Append(" inner join bar_ProductBarCode_info bars on bars.barCode=tem.barCode ");
                                                        sb.Append("where tempCode='" + obj["tempCode"].ToString() + "'");
                                                        sb.Append(" group by bars.proCode");
                                                        var scanTable = cmd.GetDataTable(sb.ToString());//获取扫描单下的所有扫描记录    
                                                        var nowIQuantity = 0.0m;
                                                        var scanIQuantity = 0.0m;
                                                        if (scanTable != null && scanTable.Rows.Count > 0)
                                                        {
                                                            var selectscan = scanTable.Select("proCode='" + item["proCode"].ToString().Trim() + "' ");
                                                            if (selectscan != null && selectscan.Length > 0)
                                                            {
                                                                foreach (DataRow row in selectscan)
                                                                {
                                                                    scanIQuantity += Convert.ToDecimal(row["number"].ToString());
                                                                }
                                                            }
                                                        }
                                                        nowIQuantity = scanIQuantity + Convert.ToDecimal(item["number"].ToString());
                                                        #endregion
                                                        if ((iQuantity>0 && iQuantity < nowIQuantity) || (iQuantity < 0 && iQuantity > nowIQuantity))
                                                        {
                                                            rsl.Result = false;
                                                            rsl.Message = string.Format("扫描数量已超出相应发货单数量，存货编码:{0},发货单数量:{1},扫描数量:{2};是否继续?",
                                                                item["proCode"].ToString(), iQuantity, nowIQuantity);
                                                            return rsl;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                    }

                                    //材料出库
                                    if (obj["inOutType"].ToString().Equals("pom"))
                                    {
                                        #region 判断扫描条码是不是计划占用的条码
                                        var sql = $@"SELECT * from V_PI_ProductsOccupation
where isdel = 0 and plCode = '{obj["outOrderCode"].ToString()}' and barCode='{obj["barCode"].ToString()}'
order by barStatus desc";
                                        var dt = cmd.GetDataTable(sql);

                                        if (dt.Rows.Count <= 0)
                                        {
                                            rsl.Message = "扫描标签未被当前计划占用，不可出库";
                                            rsl.Result = false;
                                            return rsl;
                                        }

                                        #endregion
                                    }
                                }
                                #endregion 

                                #region 调拨操作
                                if (obj["operateType"].ToString().Equals("03"))
                                {
                                    #region 出库时判断是否和条码所在的仓库相同
                                    if (string.IsNullOrWhiteSpace(item["wareHouse"].ToString()) || item["wareHouse"].ToString().Equals("-"))
                                    {
                                        rsl.Message = "扫描的标签没有仓库信息，请确定是否入库";
                                        rsl.Result = false;
                                        return rsl;
                                    }
                                    //if (string.IsNullOrWhiteSpace(item["warePosition"].ToString()) || item["warePosition"].ToString().Equals("-"))
                                    //{
                                    //    rsl.Message = "扫描的条码没有货位信息，请确定是否入库";
                                    //    rsl.Result = false;
                                    //    return rsl;
                                    //}
                                    if (!obj["wareHouse"].ToString().Equals(item["wareHouse"].ToString()))
                                    {
                                        rsl.Message = "选择的发生仓库不存在扫描的标签信息";
                                        rsl.Result = false;
                                        return rsl;
                                    }
                                    //旭日无货位
                                    //if (isWarePosition(item["wareHouse"].ToString(), obj["baseCode"].ToString()) && string.IsNullOrWhiteSpace(item["warePosition"].ToString()))
                                    //{
                                    //    rsl.Message = "选择的发生仓库有货位管理，扫描的条码上必须有货位";
                                    //    rsl.Result = false;
                                    //    return rsl;
                                    //}
                                    //if (isWarePosition(obj["targetWareHouse"].ToString(), obj["baseCode"].ToString()) && string.IsNullOrWhiteSpace(obj["targetGoodsPosition"].ToString()))
                                    //{
                                    //    rsl.Message = "选择的目标仓库有货位管理，必须选择目标货位";
                                    //    rsl.Result = false;
                                    //    return rsl;
                                    //}
                                    #endregion

                                    #region 货位调拨 已注释
                                    //if (obj["inOutType"].ToString().Equals("pag"))
                                    //{
                                    //    if (!obj["goodsPosition"].ToString().Equals(item["warePosition"].ToString()))
                                    //    {
                                    //        rsl.Message = "选择的发生货位不存在扫描的条码信息";
                                    //        rsl.Result = false;
                                    //        return rsl;
                                    //    }
                                    //}
                                    #endregion

                                }
                                #endregion
                            }
                            #endregion
                        }
                        else
                        {
                            rsl.Result = false; //条码错误
                            return rsl;
                        }
                        rsl = serviceBLL.AddScanTempRecord(number, jsonStr, ref operList);
                        if (!rsl.Result)
                        {
                            return rsl;
                        }
                    }

                    //往扫描临时表中添加数据
                    rsl = cmd.MoreUpdate(operList);
                    if (rsl.Result)
                    {
                        var barNumber = 0;
                        #region 获取该临时码中扫描的条码个数
                        sb.Clear();
                        sb.Append("select barCode,createuser from  bar_TempScanData_info ");
                        sb.Append("where tempCode='" + obj["tempCode"].ToString() + "'");
                        var scanTable = cmd.GetDataTable(sb.ToString());//获取扫描单下的所有扫描记录    
                        if (scanTable != null && scanTable.Rows.Count > 0)
                        {
                            barNumber = scanTable.Rows.Count;
                        }
                        var dic = new Dictionary<string, string>();
                        dic["barNumber"] = barNumber.ToString();
                        rsl.Data = dic;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        ///获取条码的状态信息
        /// </summary>
        /// <param name="barStatus"></param>
        /// <returns></returns>
        public string getBarStatus(string barStatus)
        {

            sb = new StringBuilder();
            var status = "";
            sb.Append(" select name from sys_dictionaries_info where status=1 ");
            if (!string.IsNullOrWhiteSpace(barStatus))
            {
                sb.Append(" and code='" + barStatus + "'");
            }
            var dt = cmd.GetDataTable(sb.ToString());
            if (dt.Rows.Count > 0)
            {
                status = dt.Rows[0]["name"].ToString();
            }
            return status;
        }

        ///// <summary>
        /// 获取出入库扫描单号里的所有条码数据
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getInputList(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                scan = new DbTempScanData();
                oper = new OperateModel();
                StringBuilder sb = new StringBuilder();
                List<SqlParameter> sqlList = new List<SqlParameter>();
                Dictionary<string, string> dic = new Dictionary<string, string>();
                Dictionary<string, object> dicList = new Dictionary<string, object>();
                List<int> widthList = new List<int>();//每列的宽度
                #region 获取出入库扫描单号的所有数据
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                //解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);

                if (!string.IsNullOrWhiteSpace(json["tempCode"].ToString()))
                {
                    scan.tempCode = json["tempCode"].ToString();
                    scan.operateType = json["operateType"].ToString();
                    var scanList = cmd.GetDataByObject<DbTempScanData>(scan);//获取所有的扫描单号
                    if (scanList.Count > 0)
                    {
                        string barCode = string.Empty;
                        for (int i = 0; i < scanList.Count; i++)
                        {
                            if (scanList[i].barCode != null && !string.IsNullOrWhiteSpace(scanList[i].barCode.ToString()))
                            {
                                barCode += "'" + scanList[i].barCode.ToString() + "'" + ",";
                            }
                        }
                        #region 数据列表
                        if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                        {
                            if (json["inOutType"].ToString().Equals("pibg") || json["inOutType"].ToString().Equals("pobg"))
                            {
                                sb.Clear();
                                sb.Append("select byBarCode as barCode,byCode,banchang,banzhou,'1' number,i.proName ");
                                sb.Append("from fun_BanYang_list b ");
                                sb.Append("inner join fun_Inventory_Info i on i.proCode=b.erpProCode ");
                                sb.Append("where b.baseCode='" + json["baseCode"].ToString() + "' ");
                                sb.Append(" and byBarCode in(" + barCode.TrimEnd(',') + ")");
                                sb.Append(" and b.isdel=0 and dTypes='bg' ");
                            }
                            //else if (json["inOutType"].ToString().Equals("piyb") || json["inOutType"].ToString().Equals("poyb"))
                            //{
                            //    sb.Clear();
                            //    sb.Append("select yCode as barCode,yName,shuliang,weizhi,ystatusName,proCount ");
                            //    sb.Append(" from V_YangBan_info ");
                            //    sb.Append(" where 1=1 ");
                            //    sb.Append(" and yCode in(" + barCode.TrimEnd(',') + ") ");
                            //    sb.Append(" and isdel=0 ");
                            //}
                            else
                            {
                                sb.Clear();
                                sb.Append(getBarInfoList(barCode.TrimEnd(','), json["baseCode"].ToString()));
                            }
                        }
                        var dt = cmd.GetDataTable(sb.ToString());

                        var list = cmd.TableToDictionary(dt);
                        #endregion

                        dic = new Dictionary<string, string>();
                        #region 列名
                        if (json.Property("inOutType") != null && !string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                        {
                            if (json["inOutType"].ToString().Equals("pibg") || json["inOutType"].ToString().Equals("pobg"))
                            {
                                var widths = new int[] { 150, 150, 150, 150 };
                                widthList = widths.ToList();
                                dic.Add("barCode", "版辊编码");
                                dic.Add("byCode", "版号");
                                dic.Add("banchang", "版长");
                                dic.Add("banzhou", "版周");
                                //dic.Add("banzhi", "版支数");
                                //dic.Add("banhao", "版号");
                                //dic.Add("weizhi", "位置");
                                //dic.Add("customName", "客户名称");
                                //dic.Add("zbcjName", "制版厂家");
                                //dic.Add("bstatusName", "条码状态");
                            }
                            else if (json["inOutType"].ToString().Equals("piyb") || json["inOutType"].ToString().Equals("poyb"))
                            {
                                var widths = new int[] { 150, 150, 150, 150, 150, 150 };
                                widthList = widths.ToList();
                                dic.Add("barCode", "条码编码");
                                dic.Add("yName", "样版名称");
                                dic.Add("shuliang", "数量");
                                dic.Add("weizhi", "位置");
                                dic.Add("proCount", "存货数量");
                                dic.Add("ystatusName", "条码状态");
                            }
                            else
                            {
                                var widths = new int[] { 150, 150, 150, 150, 150, 150, 200, 200, 150, 150, 150, 150 };
                                widthList = widths.ToList();
                                dic.Add("barCode", "条码号");
                                dic.Add("proCode", "存货编码");
                                dic.Add("proName", "存货名称");
                                dic.Add("proStyle", "存货类型");
                                dic.Add("width", "宽度");
                                //dic.Add("goodsPositionName", "货位名称");
                                dic.Add("plCode", "生产计划单");
                                dic.Add("pSpec", "生产类型");
                                dic.Add("zhongliang", "重量");
                                dic.Add("mishu", "每件米数");
                                dic.Add("userName", "创建人");
                            }
                        }
                        #endregion

                        if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                        {
                            #region 构建列表数据
                            #region 构建列表元素显示格式
                            var headList = new List<object>();
                            var hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "barCode", "条码号");
                            headList.Add(hList);
                            hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "plCode", "生产计划单");
                            headList.Add(hList);
                            hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "number", "数量");
                            //createHead(ref hList, "zhongliang", "重量");
                            headList.Add(hList);
                            //hList = new List<Dictionary<string, string>>();
                            //createHead(ref hList, "barList", "明细信息");
                            //headList.Add(hList);
                            hList = new List<Dictionary<string, string>>();
                            if (json["inOutType"].ToString() == "pobg" || json["inOutType"].ToString() == "pibg")
                            {
                                createHead(ref hList, "barCode", "版辊编码");
                                createHead(ref hList, "byCode", "版号");
                                //createHead(ref hList, "banchang", "版长");
                                //createHead(ref hList, "banzhou", "版周");
                            }
                            else
                            {
                                createHead(ref hList, "proCode", "存货编码");
                                createHead(ref hList, "proStyle", "规格");
                            }
                            headList.Add(hList);
                            hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "proName", "存货名称");
                            headList.Add(hList);
                            #endregion

                            #region 数据分页显示
                            //总条数
                            var pageCount = "0";
                            //总页数
                            var pageNumber = "0";
                            //每页条数
                            var pageSize = "20";
                            var paraList = cmd.getParam("appPageSize");
                            if (paraList != null && paraList.Count > 0)
                            {
                                if (!string.IsNullOrWhiteSpace(paraList[0].parValue))
                                {
                                    pageSize = paraList[0].parValue;
                                }
                            }
                            var table = cmd.PageTableList(dt, json["pageIndex"].ToString(), pageSize, ref pageCount, ref pageNumber);


                            var temlist = cmd.TableToDictionary(table);
                            var listInfo = new Dictionary<string, object>();
                            listInfo.Add("head", headList);
                            listInfo.Add("list", temlist);

                            #endregion

                            listInfo.Add("pageNumber", pageNumber);
                            var pageIndex = int.Parse(json["pageIndex"].ToString());
                            listInfo.Add("pageIndex", pageIndex.ToString());
                            dicList.Add("listInfo", listInfo);
                            #endregion

                            #region 构建汇总数据
                            headList = new List<object>();
                            hList = new List<Dictionary<string, string>>();
                            createHead(ref hList, "count", "总件数");
                            createHead(ref hList, "number", "总数量");
                            headList.Add(hList);
                            //hList = new List<Dictionary<string, string>>();
                            //createHead(ref hList, "weight", "总重量");
                            //headList.Add(hList);
                            #region 汇总列表中信息
                            var sumDic = new Dictionary<string, string>();
                            var number = 0m;
                            var count = 0;
                            var weight = 0.0m;
                            var meter = 0.0m;

                            if (list != null && list.Count > 0)
                            {
                                foreach (var item in list)
                                {
                                    var proNumber = item["number"].ToString();
                                    //var proWeight = item["zhongliang"].ToString();
                                    //var proMeter = item["mishu"].ToString();
                                    if (!string.IsNullOrWhiteSpace(proNumber) && Convert.ToDecimal(proNumber) > 0)
                                    {
                                        number += Convert.ToDecimal(proNumber);
                                    }
                                    //if (!string.IsNullOrWhiteSpace(proWeight) && Convert.ToDecimal(proWeight) > 0)
                                    //{
                                    //    weight += Convert.ToDecimal(proWeight);
                                    //}
                                    //if (!string.IsNullOrWhiteSpace(proMeter) && Convert.ToDecimal(proMeter) > 0)
                                    //{
                                    //    meter += Convert.ToDecimal(proMeter);
                                    //}
                                }
                                count = list.Count;
                            }
                            sumDic.Add("count", count.ToString());
                            sumDic.Add("number", number.ToString());
                            //sumDic.Add("weight", Convert.ToDecimal(weight).ToString("F2"));
                            var sumDicList = new List<Dictionary<string, string>>();
                            sumDicList.Add(sumDic);
                            #endregion
                            var sumList = new Dictionary<string, object>();
                            sumList.Add("head", headList);
                            sumList.Add("list", sumDicList);
                            dicList.Add("sumList", sumList);
                            #endregion

                        }
                        else
                        {
                            list.Insert(0, dic);
                            dicList.Add("widthList", widthList);
                            dicList.Add("list", list);
                        }


                        rsl.Data = dicList;
                        rsl.Result = true;
                    }
                    else
                    {
                        rsl.Message = "没有数据";
                        rsl.Data = false;
                        return rsl;
                    }
                }
                else
                {
                    rsl.Message = "没有数据";
                    rsl.Data = false;
                    return rsl;
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 获取列表条码信息
        /// </summary>
        /// <param name="barCodes"></param>
        /// <param name="baseCode"></param>
        /// <returns></returns>
        private string getBarInfoList(string barCodes, string baseCode)
        {
            sb = new StringBuilder();
            if (!string.IsNullOrWhiteSpace(barCodes) && !string.IsNullOrWhiteSpace(baseCode))
            {
                sb.Append("select bar.barCode,inv.proCode,inv.proName,inv.spec as proStyle, ");
                sb.Append(" bar.number,bar.planCode as plCode,bar.proWeight as zhongliang,bar.proMeter as mishu,bar.pusers as userName,  ");
                sb.Append(" bar.barStatus ");   //wp.cName  goodsPositionName, 
                sb.Append("  from bar_ProductBarCode_info bar ");
                sb.Append(" left join fun_Inventory_Info inv on bar.proCode = inv.proCode ");
                sb.Append(" and inv.isDel=0 and inv.baseCode='" + baseCode + "' ");
                //sb.Append(" left join fun_CommonData_Info wp on wp.cCode = bar.warePosition and wp.cType='WP'");
                //sb.Append(" and wp.isDel=0 and wp.status='Y' and wp.specFile='" + baseCode + "'");
                sb.Append(" where bar.barCode in(" + barCodes + ")");
            }
            return sb.ToString();
        }


        /// <summary>
        /// 删除临时码的临时数据
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult deleteScanRecord(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 删除临时数据
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                DbTempScanData temp = new DbTempScanData();
                List<OperateModel> operList = new List<OperateModel>();
                if (!string.IsNullOrWhiteSpace(json["tempCode"].ToString()))
                {
                    if (!string.IsNullOrWhiteSpace(json["inOutType"].ToString()))
                    {
                        temp.tempCode = json["tempCode"].ToString();
                        temp.inOutType = json["inOutType"].ToString();
                        if (json["ioTypeCode"] != null && !string.IsNullOrEmpty(json["ioTypeCode"].ToString()))
                        {
                            temp.inOutType = json["ioTypeCode"].ToString();
                        }
                        oper = new OperateModel();
                        oper.Data = temp;
                        oper.Conditions = "tempCode,inOutType";
                        oper.Types = OperateModel.OperateType.Delete;
                        operList.Add(oper);
                        rsl = cmd.MoreUpdate(operList);
                    }
                }
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 获取发货单列表
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getSaleOrderList(string jsonStr)
        {
            rsl = new ReturnResult();
            #region 获取销售订单信息
            try
            {
                List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                Dictionary<string, object> dic = new Dictionary<string, object>();
                List<int> widthList = new List<int>();//列宽度列表
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
     

                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                _log.Info("getSaleOrderList方法：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                sb.Append(" select top 100 dis.cDLCode,cus.cCusName,per.cPersonName as personName,convert(varchar(50),convert(date,dis.dDate))  dDate ");
                sb.Append(" ,dis.DLID id,dis.cDepCode,dep.cDepName,cus.cCusCode,dis.cPersonCode as personCode ");
                sb.Append(" from DispatchList dis ");
                sb.Append(" inner join (select distinct DLID from DispatchLists where cSCloser is null ");
                sb.Append(" and ( (convert(decimal(18,2),iQuantity)>0 and  convert(decimal(18,2),iQuantity)>convert(decimal(18,2),fOutQuantity)) ");  //发货单 和 退货单
                sb.Append(" or (convert(decimal(18,2),iQuantity)<0 and  convert(decimal(18,2),iQuantity)<convert(decimal(18,2),isnull(fOutQuantity,0)) ) ) ");  //发货单不会手动关闭，只要累计出库数量<发货单数量的
                sb.Append("  ) diss on dis.DLID =diss.DLID    ");
                sb.Append(" left join  Customer cus on cus.cCusCode=dis.cCusCode ");
                sb.Append(" left join  Person per on dis.cPersonCode = per.cPersonCode ");
                sb.Append(" left join Department dep on dis.cDepCode=dep.cDepCode ");
                sb.Append(" where isnull(dis.cVerifier,'') <>'' and isnull(dis.dverifydate,'') <>''  ");
                #region  检索条件
                //移动端查询
                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    if (json.Property("orderCode") != null && !string.IsNullOrWhiteSpace(json["orderCode"].ToString()))
                    {
                        sb.Append(" and dis.cDLCode like '%" + json["orderCode"].ToString().Trim() + "%' ");
                    }
                    if (json.Property("cuName") != null && !string.IsNullOrWhiteSpace(json["cuName"].ToString()))
                    {
                        sb.Append(" and cus.cCusName like '%" + json["cuName"].ToString().Trim() + "%' ");
                    }
                    if (json.Property("date") != null && !string.IsNullOrWhiteSpace(json["date"].ToString()))
                    {
                        sb.Append(" and convert(date,dis.dDate) = '" + json["date"].ToString().Trim() + "' ");
                    }
                    if (json.Property("isBlue") != null && !string.IsNullOrWhiteSpace(json["isBlue"].ToString()))
                    {
                        var bReturnFlag = 0;
                        if (json["isBlue"].ToString().Trim().Equals("0"))
                        {
                            bReturnFlag = 1;
                        }
                        sb.Append(" and dis.bReturnFlag = '" + bReturnFlag + "' ");
                    }

                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(json["conditions"].ToString()))
                    {
                        sb.Append(" and (dis.cDLCode like '%" + json["conditions"] + "%' ");
                        sb.Append(" or cus.cCusName like '% " + json["conditions"].ToString() + "%'");//客户名称
                        sb.Append(" or per.cPersonName like '% " + json["conditions"].ToString() + "%')");//存货编码
                    }
                }
                #endregion
                sb.Append(" order by dis.dDate desc,dis.cDLCode desc ");

                var table =outBase.getData(sb.ToString(), json["baseCode"].ToString());
                if (table.Rows.Count <= 0)
                {
                    rsl.Result = false;
                    rsl.Message = "没有数据";
                    return rsl;
                }

                var saleList = cmd.TableToDictionary(table);

                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    #region 构建表头数据
                    var headData = new List<object>();
                    var head = new Dictionary<string, string>();
                    var obj = new { field = "cDLCode", name = "发货单", width = "150" };
                    headData.Add(obj);
                    obj = new { field = "cCusName", name = "客户名称", width = "150" };
                    headData.Add(obj);
                    obj = new { field = "personName", name = "业务员", width = "150" };
                    headData.Add(obj);
                    obj = new { field = "dDate", name = "创建时间", width = "80" };
                    headData.Add(obj);
                    #endregion
                    dic.Add("headData", headData);
                    dic.Add("list", saleList);
                }
                else
                {
                    Dictionary<string, string> temdic = new Dictionary<string, string>();
                    var widths = new int[] { 150, 150, 150, 150 };
                    widthList = widths.ToList();
                    temdic.Add("cDLCode", "发货单");
                    temdic.Add("cCusName", "客户名称");//实际客户
                    temdic.Add("personName", "业务员");//实际业务员
                    temdic.Add("dDate", "创建时间");
                    saleList.Insert(0, temdic);
                    dic.Add("widthList", widthList);
                    dic.Add("list", saleList);
                }

                rsl.Data = dic;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }

        /// <summary>
        /// 获取发货单明细对应扫描临时表中各行的汇总
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getTemScanSaleOrderList(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "未获取到请求参数";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);

                #region 获取发货单数据
                sb.Clear();
                //cDefine1实际客户(客户名称在U8是唯一的)，cDefine2实际业务员
                sb.Clear();
                sb.Append("select inv.cInvName,isnull(sum(convert(decimal(18,2),isnull(mains.iQuantity,0))),0) iQuantity,  ");//填写U8销售订单信息
                sb.Append(" isnull(sum(convert(decimal(18,2),isnull(mains.fOutQuantity,0))),0) fOutQuantity,mains.cInvCode  ");
                sb.Append(" from DispatchList main ");
                sb.Append(" inner join DispatchLists mains on main.DLID = mains.DLID  ");
                sb.Append(" inner join inventory inv on inv.cInvCode=mains.cInvCode ");
                sb.Append("  where isnull(main.cVerifier,'') <>'' and isnull(main.dverifydate,'') <>''  ");
                sb.Append("  and main.cDLCode='" + json["outOrderCode"].ToString() + "' ");
                sb.Append(" group by inv.cInvName,mains.cInvCode ");
                var orderDt = outBase.getData(sb.ToString(), json["baseCode"].ToString());

                var list = cmd.TableToDictionary(orderDt);

                #endregion 获取发货单数据
                #region 获取扫描临时表中条码数据
                sb.Clear();
                sb.Append("select bars.proCode,sum(convert(decimal(18,2),isnull(bars.number,0))) number  ");
                sb.Append(",count(bars.barCode) barC ");
                sb.Append(" from bar_TempScanData_info tem ");
                sb.Append(" inner join bar_ProductBarCode_info bars on bars.barCode=tem.barCode ");
                sb.Append(" where 1=1 and tem.tempCode='" + json["tempCode"].ToString() + "' ");
                sb.Append(" group by bars.proCode ");
                var barDt = cmd.GetDataTable(sb.ToString());
                #endregion 获取扫描临时表中条码数据

                #region 统计各个存货中扫描的条数

                foreach (var s in list)
                {
                    var number = 0m;
                    var count = 0m;

                    if (barDt != null && barDt.Rows.Count > 0)
                    {
                        var selectStr = "proCode='" + s["cInvCode"] + "' ";
                        var barLength = barDt.Select(selectStr);
                        if (barLength != null && barLength.Length > 0)
                        {
                            foreach (DataRow item in barLength)
                            {
                                number += Decimal.Parse(item["number"].ToString());
                                count += Decimal.Parse(item["barC"].ToString());
                            }

                        }
                    }

                    s["scanNum"] = number.ToString();
                    s["scanCou"] = count.ToString();
                }

                //if (orderDt != null && orderDt.Rows.Count > 0)
                //{
                //    orderDt.Columns.Add("scanNum");//添加扫描列
                //    orderDt.Columns.Add("scanCou");//添加扫描列
                //    for (int i = 0; i < orderDt.Rows.Count; i++)
                //    {
                //        var row = orderDt.Rows[i];
                //        var number = 0m;
                //        var count = 0m;
                //        if (barDt != null && barDt.Rows.Count > 0)
                //        {
                //            var selectStr = "proCode='" + row["cInvCode"] + "' ";
                //            var barLength = barDt.Select(selectStr);
                //            if (barLength != null && barLength.Length > 0)
                //            {
                //                foreach (DataRow item in barLength)
                //                {
                //                    number += Decimal.Parse(item["number"].ToString());
                //                    count += Decimal.Parse(item["barC"].ToString());
                //                }

                //            }
                //        }
                //        row["scanNum"] = number;
                //        row["scanCou"] = count;
                //    }
                //}
                #endregion 统计各个存货中扫描的条数

                #region 构建表头数据 已注释
                //var headData = new List<object>();
                //var head = new Dictionary<string, string>();
                //var obj = new { field = "cInvCode", name = "存货编码", width = "90" };
                //headData.Add(obj);
                //obj = new { field = "cInvName", name = "存货名称", width = "130" };
                //headData.Add(obj);
                //obj = new { field = "iQuantity", name = "发货数量", width = "70" };
                //headData.Add(obj);
                //obj = new { field = "fOutQuantity", name = "累计发货数", width = "70" };
                //headData.Add(obj);
                //obj = new { field = "scanNum", name = "扫描数量", width = "60" };
                //headData.Add(obj);
                #endregion

                //var dic = new Dictionary<string, object>();
                //dic.Add("headData", headData);
                //dic.Add("list", cmd.TableToDictionary(orderDt));

                rsl.Result = true;
                //rsl.Data = dic;
                rsl.Data = list;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

















        /// <summary>
        /// 获取系统字典表参数
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getDictionaryInfo(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "请求参数不能为空";
                    return rsl;
                }
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                sb.Clear();
                sb.Append("select * from sys_dictionaries_info where 1=1 and status=1 ");
                if (json.Property("code") != null && !string.IsNullOrWhiteSpace(json["code"].ToString()))
                {
                    sb.Append(" and code='" + json["code"].ToString() + "' ");
                }
                if (json.Property("name") != null && !string.IsNullOrWhiteSpace(json["name"].ToString()))
                {
                    sb.Append(" and name='" + json["name"].ToString() + "' ");
                }
                if (json.Property("types") != null && !string.IsNullOrWhiteSpace(json["types"].ToString()))
                {
                    sb.Append(" and types='" + json["types"].ToString() + "' ");
                }
                if (json.Property("extendFile") != null && !string.IsNullOrWhiteSpace(json["extendFile"].ToString()))
                {
                    sb.Append(" and extendFile='" + json["extendFile"].ToString() + "' ");
                }
                var sysDt = cmd.GetDataTable(sb.ToString());
                var list = new List<object>();
                if (sysDt != null && sysDt.Rows.Count > 0)
                {
                    foreach (DataRow item in sysDt.Rows)
                    {
                        var temDic = new Dictionary<string, string>();
                        temDic["value"] = item["code"].ToString();
                        temDic["text"] = item["name"].ToString();
                        list.Add(temDic);
                    }
                }
                rsl.Result = true;
                rsl.Data = list;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }


        /// <summary>
        /// 获取盘点任务信息列表（H5端）
        /// </summary>
        public ReturnResult getCheckTaskList(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var dicList = new Dictionary<string, object>();
                #region 获取盘点任务
                var tableName = "";
                sb.Clear();
                sb.Append("select *  ");
                //sb.Append("(isnull(proCode,'')+'/'+isnull(proName,'')+'/'+isnull(spec,'')) as proNsp,  ");
                //sb.Append("(isnull(color,'')+'/'+isnull(shangbiao,'')) colorBiao ");
                sb.Append(" from V_pch_ProCheckTask_info where 1=1 ");
                sb.Append(" and convert(int,isdel)<>1 ");  //and baseCode='" + json["baseCode"].ToString() + "'
                tableName = sb.ToString();
                sb.Clear();
                sb.Append(" status='pct-doing' ");
                //仓库编码
                if (json.Property("wareHouse") != null && !string.IsNullOrWhiteSpace(json["wareHouse"].ToString()))
                {
                    sb.Append(" and erpWareCode ='" + json["wareHouse"].ToString() + "' ");
                }
                //货位编码
                if (json.Property("goodsPosition") != null && !string.IsNullOrWhiteSpace(json["goodsPosition"].ToString()))
                {
                    sb.Append(" and erpPositionCode ='" + json["goodsPosition"].ToString() + "' ");
                }
                //盘点单号
                if (json.Property("pdCode") != null && !string.IsNullOrWhiteSpace(json["pdCode"].ToString()))
                {
                    sb.Append(" and venCode like '%" + json["pdCode"].ToString() + "%' ");
                }
                //关联单号
                if (json.Property("erpCode") != null && !string.IsNullOrWhiteSpace(json["erpCode"].ToString()))
                {
                    sb.Append(" and erpCode like '%" + json["erpCode"].ToString() + "%' ");
                }
                //存货名称
                if (json.Property("proName") != null && !string.IsNullOrWhiteSpace(json["proName"].ToString()))
                {
                    sb.Append(" and proName  like '%" + json["proName"].ToString() + "%' ");
                }
                //报工时间
                if (json.Property("date") != null && json["date"] != null)
                {
                    var date = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(json["date"]));
                    if (date != null && date.Length > 1)
                    {
                        var sDate = date[0].ToString();
                        var eDate = date[1].ToString();
                        sb.Append(" and convert(date,createtime) >= '" + sDate + "'");
                        sb.Append(" and convert(date,createtime) <= '" + eDate + "'");
                    }
                }
                var sqlWhere = sb.ToString();
                var orderStr = " createtime desc ";
                //var dt = cmd.GetDataTable(sb.ToString());
                #region 构建列表数据
                #region 构建列表元素显示格式
                var headList = new List<object>();
                var hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "venCode", "盘点单号");
                createHead(ref hList, "erpCode", "关联单据");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "createtime", "创建时间");
                headList.Add(hList);
                //hList = new List<Dictionary<string, string>>();
                //createHead(ref hList, "proNsp", "存货", "#000", "20");
                //headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "chTypeName", "盘点类型");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "wareName", "盘点仓库");
                //createHead(ref hList, "positionName", "盘点货位");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "statusName", "任务状态");
                createHead(ref hList, "createuserName", "创建人");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "erpNumber", "用友账面数");
                createHead(ref hList, "scanNumber", "已盘数量");
                headList.Add(hList);
                #endregion

                #region 数据分页显示
                //总条数
                var pageCount = "0";
                //总页数
                var pageNumber = "0";
                //每页条数
                var pageSize = "20";
                var paraList = cmd.getParam("appPageSize");
                if (paraList != null && paraList.Count > 0)
                {
                    if (!string.IsNullOrWhiteSpace(paraList[0].parValue))
                    {
                        pageSize = paraList[0].parValue;
                    }
                }
                #region 自动定位列表信息位置功能
                var table = new DataTable();
                var pageIndex = int.Parse(json["pageIndex"].ToString());
                if (json.Property("selectIndex") != null && !string.IsNullOrWhiteSpace(json["selectIndex"].ToString()) && int.Parse(json["selectIndex"].ToString()) > 0)
                {
                    var page = int.Parse(json["selectIndex"].ToString()) / int.Parse(pageSize);
                    var syCount = int.Parse(json["selectIndex"].ToString()) % int.Parse(pageSize);
                    if (syCount > 0)
                    {
                        page += 1;
                    }
                    var allCount = page * int.Parse(pageSize);//页数的总条数
                    //如果但前索引与到当前页所有数据的总条数相差5就再多请求一页数据；
                    if ((allCount - int.Parse(json["selectIndex"].ToString())) < 5)
                    {
                        page += 1;
                    }
                    //一次性请求的数据
                    var tempageNumber = "0";
                    var tempageCount = "0";
                    var tempageSize = (page * int.Parse(pageSize)).ToString();
                    ////获取正常分页的总页数
                    //table = cmd.PageTableList(dt, "1", pageSize, ref pageCount, ref pageNumber);
                    ////获取一次性到达定位页的所有数据
                    //table = cmd.PageTableList(dt, "1", tempageSize, ref tempageCount, ref tempageNumber);
                    //获取正常分页的总页数
                    table = cmd.PageTableList(tableName, "1", pageSize, sqlWhere, orderStr, ref pageCount, ref pageNumber);
                    //获取一次性到达定位页的所有数据
                    table = cmd.PageTableList(tableName, "1", tempageSize, sqlWhere, orderStr, ref tempageCount, ref tempageNumber);
                    pageIndex = page;//当前页为定位到的页码
                }
                else
                {
                    //table = cmd.PageTableList(dt, json["pageIndex"].ToString(), pageSize, ref pageCount, ref pageNumber);
                    table = cmd.PageTableList(tableName, json["pageIndex"].ToString(), pageSize, sqlWhere, orderStr, ref pageCount, ref pageNumber);
                }
                #endregion
                table.Columns.Add("scanNumber");
                #region 获取盘点任务的已盘条码数量
                if (table != null && table.Rows.Count > 0)
                {
                    var pchCodes = "";
                    foreach (DataRow item in table.Rows)
                    {
                        item["scanNumber"] = "0";
                        pchCodes += "'" + item["pchCode"].ToString() + "'" + ",";
                    }
                    if (!string.IsNullOrWhiteSpace(pchCodes.TrimEnd(',')))
                    {
                        sb.Clear();
                        sb.Append("select * from pCh_CheckTask_records where 1=1 ");
                        sb.Append(" and pchCode in(" + pchCodes.TrimEnd(',') + ") ");
                        var barDt = cmd.GetDataTable(sb.ToString());
                        if (barDt != null && barDt.Rows.Count > 0)
                        {
                            foreach (DataRow item in table.Rows)
                            {
                                var selectRow = barDt.Select("pchCode='" + item["pchCode"].ToString() + "'");
                                if (selectRow != null && selectRow.Length > 0)
                                {
                                    item["scanNumber"] = selectRow.Length.ToString();
                                }
                            }
                        }
                    }
                }
                #endregion
                var temlist = cmd.TableToDictionary(table);
                #endregion
                var listInfo = new Dictionary<string, object>();
                listInfo.Add("head", headList);
                listInfo.Add("list", temlist);
                listInfo.Add("pageNumber", pageNumber);
                listInfo.Add("pageIndex", pageIndex.ToString());
                dicList.Add("listInfo", listInfo);
                #endregion
                #endregion
                rsl.Data = dicList;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }

        /// <summary>
        /// 获取盘点报告信息列表（H5端）
        /// </summary>
        public ReturnResult getCheckTaskReportList(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var dicList = new Dictionary<string, object>();
                #region 获取盘点报告
                var tableName = "";
                sb.Clear();
                sb.Append("select * ");
                sb.Append(" from V_pch_proCheckTask_report where 1=1  ");
                //sb.Append("   and baseCode='" + json["baseCode"].ToString() + "'");
                tableName = sb.ToString();
                sb.Clear();
                sb.Append(" 1=1 ");
                //仓库编码
                if (json.Property("wareHouse") != null && !string.IsNullOrWhiteSpace(json["wareHouse"].ToString()))
                {
                    sb.Append(" and erpWareCode ='" + json["wareHouse"].ToString() + "' ");
                }
                //货位编码
                if (json.Property("goodsPosition") != null && !string.IsNullOrWhiteSpace(json["goodsPosition"].ToString()))
                {
                    sb.Append(" and erpPositionCode ='" + json["goodsPosition"].ToString() + "' ");
                }
                //盘点单号
                if (json.Property("pdCode") != null && !string.IsNullOrWhiteSpace(json["pdCode"].ToString()))
                {
                    sb.Append(" and erpCode like '%" + json["pdCode"].ToString() + "%' ");
                }
                //存货名称
                if (json.Property("proName") != null && !string.IsNullOrWhiteSpace(json["proName"].ToString()))
                {
                    sb.Append(" and proName  like '%" + json["proName"].ToString() + "%' ");
                }
                //报工时间
                if (json.Property("date") != null && json["date"] != null)
                {
                    var date = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(json["date"]));
                    if (date != null && date.Length > 1)
                    {
                        var sDate = date[0].ToString();
                        var eDate = date[1].ToString();
                        sb.Append(" and convert(date,createtime) >= '" + sDate + "'");
                        sb.Append(" and convert(date,createtime) <= '" + eDate + "'");
                    }
                }
                var sqlWhere = sb.ToString();

                var orderStr = " createtime desc ";
                //var dt = cmd.GetDataTable(sb.ToString());
                #region 构建列表数据
                #region 构建列表元素显示格式
                var headList = new List<object>();
                var hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "erpCode", "盘点单号");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "createtime", "创建时间");
                headList.Add(hList);
                //hList = new List<Dictionary<string, string>>();
                //createHead(ref hList, "proNsp", "存货", "#000", "20");
                //headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                //createHead(ref hList, "colorBiao", "类型");
                createHead(ref hList, "chTypeName", "盘点类型");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "wareName", "盘点仓库");
                //createHead(ref hList, "positionName", "盘点货位");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "createuserName", "创建人");
                createHead(ref hList, "erpNumber", "U8账面数");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "ypNum", "物控账面数");
                createHead(ref hList, "spNum", "实盘数");
                headList.Add(hList);
                hList = new List<Dictionary<string, string>>();
                createHead(ref hList, "pyNum", "盘盈数");
                createHead(ref hList, "pkNum", "盘亏数");
                headList.Add(hList);
                #endregion

                #region 数据分页显示
                //总条数
                var pageCount = "0";
                //总页数
                var pageNumber = "0";
                //每页条数
                var pageSize = "20";
                var paraList = cmd.getParam("appPageSize");
                if (paraList != null && paraList.Count > 0)
                {
                    if (!string.IsNullOrWhiteSpace(paraList[0].parValue))
                    {
                        pageSize = paraList[0].parValue;
                    }
                }
                #region 自动定位列表信息位置功能
                var table = new DataTable();
                var pageIndex = int.Parse(json["pageIndex"].ToString());
                if (json.Property("selectIndex") != null && !string.IsNullOrWhiteSpace(json["selectIndex"].ToString()) && int.Parse(json["selectIndex"].ToString()) > 0)
                {
                    var page = int.Parse(json["selectIndex"].ToString()) / int.Parse(pageSize);
                    var syCount = int.Parse(json["selectIndex"].ToString()) % int.Parse(pageSize);
                    if (syCount > 0)
                    {
                        page += 1;
                    }
                    var allCount = page * int.Parse(pageSize);//页数的总条数
                    //如果但前索引与到当前页所有数据的总条数相差5就再多请求一页数据；
                    if ((allCount - int.Parse(json["selectIndex"].ToString())) < 5)
                    {
                        page += 1;
                    }
                    //一次性请求的数据
                    var tempageNumber = "0";
                    var tempageCount = "0";
                    var tempageSize = (page * int.Parse(pageSize)).ToString();
                    ////获取正常分页的总页数
                    //table = cmd.PageTableList(dt, "1", pageSize, ref pageCount, ref pageNumber);
                    ////获取一次性到达定位页的所有数据
                    //table = cmd.PageTableList(dt, "1", tempageSize, ref tempageCount, ref tempageNumber);
                    //获取正常分页的总页数
                    table = cmd.PageTableList(tableName, "1", pageSize, sqlWhere, orderStr, ref pageCount, ref pageNumber);
                    //获取一次性到达定位页的所有数据
                    table = cmd.PageTableList(tableName, "1", tempageSize, sqlWhere, orderStr, ref tempageCount, ref tempageNumber);
                    pageIndex = page;//当前页为定位到的页码
                }
                else
                {
                    //table = cmd.PageTableList(dt, json["pageIndex"].ToString(), pageSize, ref pageCount, ref pageNumber);
                    table = cmd.PageTableList(tableName, json["pageIndex"].ToString(), pageSize, sqlWhere, orderStr, ref pageCount, ref pageNumber);
                }
                #endregion

                var temlist = cmd.TableToDictionary(table);
                #endregion
                var listInfo = new Dictionary<string, object>();
                listInfo.Add("head", headList);
                listInfo.Add("list", temlist);
                listInfo.Add("pageNumber", pageNumber);
                listInfo.Add("pageIndex", pageIndex.ToString());
                dicList.Add("listInfo", listInfo);
                #endregion
                #endregion
                rsl.Data = dicList;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
                return rsl;
            }
            return rsl;
        }


        /// <summary>
        /// 获取H5移动端版本号并检测是否需要更新系统
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult updateEditionApp(string jsonStr)
        {
            rsl = new ReturnResult();
            List<OperateModel> operList = new List<OperateModel>();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "传入的参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                //jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                _log.Info("updateApp()方法：" + jsonStr);
                appInfo = new AppMobilesInfo();
                if (!string.IsNullOrWhiteSpace(json["appCode"].ToString()))
                {
                    appInfo.appCode = json["appCode"].ToString();
                }
                var appInfoList = cmd.GetDataByObject<AppMobilesInfo>(appInfo);
                if (appInfoList.Count > 0)
                {
                    if (!string.IsNullOrWhiteSpace(json["versionCode"].ToString()))
                    {
                        appInfo.versionCode = json["versionCode"].ToString();
                    }
                    if (!string.IsNullOrWhiteSpace(json["appVersion"].ToString()))
                    {
                        appInfo.appVersion = json["appVersion"].ToString();
                    }
                    appInfoList = cmd.GetDataByObject<AppMobilesInfo>(appInfo);
                    _log.Info("update" + JsonConvert.SerializeObject(appInfo) + "ds:" + appInfoList.Count);
                    if (appInfoList.Count > 0)
                    {
                        sb = new StringBuilder();
                        sb.Append(" select top 1 * from [dbo].[app_updateInfo] ");
                        sb.Append(" where convert(int,versionCode) > " + json["versionCode"].ToString() + "  ");
                        sb.Append(" order by versionCode");
                        _log.Info("updatesb.ToString()" + sb.ToString());
                        var updateDt = cmd.GetDataTable(sb.ToString());
                        if (updateDt.Rows.Count > 0)
                        {
                            _log.Info("update" + JsonConvert.SerializeObject(cmd.TableToDictionary(updateDt)));
                            var row = updateDt.Rows[0];
                            var data = new Dictionary<string, object>();
                            // 版本更新内容 支持<br>自动换行
                            data["describe"] = row["versionDesc"].ToString();
                            //apk、wgt包下载地址或者应用市场地址
                            //安卓应用市场 market://details?id=xxxx
                            //苹果store itms-apps://itunes.apple.com/cn/app/xxxxxx
                            data["edition_url"] = row["downloadUrl"].ToString();
                            //是否强制更新 0代表否 1代表是
                            data["edition_force"] = row["isForced"].ToString();
                            //0是整包升级（apk或者appstore或者安卓应用市场） 1是wgt升级
                            data["package_type"] = row["isWgtPackage"].ToString();
                            //是否发行  0否 1是 为了控制上架应用市场审核时不能弹出热更新框
                            data["edition_issue"] = 1;
                            //版本号 最重要的manifest里的版本号
                            data["edition_number"] = row["versionCode"].ToString();
                            // 版本名称 manifest里的版本名称
                            data["edition_name"] = row["versionName"].ToString();
                            // 是否静默更新 0代表否 1代表是
                            data["edition_silence"] = 0;
                            rsl.Data = data;
                            rsl.Result = true;
                            return rsl;
                        }
                        else
                        {
                            rsl.Message = "无更新内容";
                            rsl.Result = true;
                            return rsl;
                        }
                    }
                    else
                    {
                        #region 添加移动端本机信息
                        appInfo.mobilesType = json["version_type"].ToString();
                        appInfo.mVendor = json["mVendor"].ToString();
                        appInfo.mModel = json["mModel"].ToString();
                        appInfo.createtime = getNow();
                        oper = new OperateModel();
                        oper.Data = appInfo;
                        oper.Types = OperateModel.OperateType.Edit;
                        oper.Conditions = "appCode";
                        operList.Add(oper);
                        #endregion
                    }
                }
                else
                {
                    #region 添加移动端本机信息
                    if (!string.IsNullOrWhiteSpace(json["versionCode"].ToString()))
                    {
                        appInfo.versionCode = json["versionCode"].ToString();
                    }
                    if (!string.IsNullOrWhiteSpace(json["appVersion"].ToString()))
                    {
                        appInfo.appVersion = json["appVersion"].ToString();
                    }
                    appInfo.mobilesType = json["version_type"].ToString();
                    appInfo.mVendor = json["mVendor"].ToString();
                    appInfo.mModel = json["mModel"].ToString();
                    appInfo.createuser = "admin";
                    appInfo.createtime = getNow();
                    appInfo.status = "1";
                    oper = new OperateModel();
                    oper.Data = appInfo;
                    oper.Types = OperateModel.OperateType.Add;
                    operList.Add(oper);
                    #endregion
                }
                rsl = cmd.MoreUpdate(operList);
                if (!rsl.Result)
                {
                    rsl.Message = "本机信息添加失败";
                    rsl.Result = false;
                    return rsl;
                }
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }
        /// <summary>
        /// 创建消息
        /// </summary>
        /// <param name="dic">数据</param>
        /// <param name="userCode">创建人员</param>
        /// <param name="list"></param>
        public void CreateMsgInfo(Dictionary<string, object> dic, string userCode, ref List<OperateModel> list)
        {
            DbTaskCenter task;
            task = new DbTaskCenter();
            task.businessType = dic["businessType"].ToString();
            task.relationOrder = dic["businessCode"].ToString();
            task.toUser = dic["toUser"].ToString();
            task.details = JsonConvert.SerializeObject(dic["datas"]);
            task.contents = dic["contents"].ToString();
            task.createtime = getNow();
            task.createuser = userCode;
            task.isFinish = 0;
            task.memo = dic["memo"].ToString();

            oper = new OperateModel();
            oper.Data = task;
            oper.Types = OperateModel.OperateType.Add;
            list.Add(oper);
        }

        /// <summary>
        /// 移动端原辅料占用查询界面
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult MatSubOccuQuery(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "传入的参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);

                var planCode = json["planCode"].ToString();

                var sql = $@"SELECT * from V_PI_ProductsOccupation where isdel = 0 and plCode = '{planCode}' order by barStatus desc";
                var dt = cmd.GetDataTable(sql);

                var list = cmd.TableTolist<MatSubOccuView>(dt);

                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 未调拨到车间库的占用原料查询
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult needTransVouchBar(string jsonStr)
        {
            rsl = new ReturnResult();
            try
            {
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Message = "传入的参数不能为空";
                    rsl.Result = false;
                    return rsl;
                }
                jsonStr = Encryption.DesDecrypt(jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);

                var sql = "select parValue from sys_parameters_info where parCode='work_warehouse_code' and isDel='0' ";
                var dt = cmd.GetDataTable(sql);
                var cjcode = "8";
                if (dt.Rows.Count > 0)
                {
                    //cjcode = dt.Rows[0]["parValue"].ToString();
                    #region 多个仓库（Ning）
                    var ware = dt.Rows[0]["parValue"].ToString();
                    var lists = ware.Split(',');
                    for (int i = 0; i < lists.Length; i++)
                    {
                        cjcode += "'" + lists[i].ToString() + "',";
                    }
                    cjcode = cjcode.TrimEnd(',');
                    #endregion
                }

                var planCode = json["planCode"].ToString();

                //查询未调拨到车间库的占用原料条码  并且  没有被调拨扫码的
                sql = $@"SELECT b.barCode,b.proCode,b.proName,b.spec,houseName from pi_ProductsOccupation_list p inner join V_BarCode_Info b on b.barCode = p.barCode 
where p.isdel = 0 and plCode = '{planCode}' and barStatus = 'need-out' and b.wareHouse not in ({cjcode}) 
except
select b.barCode,b.proCode,b.proName,b.spec,houseName  
from bar_TempScanData_info t
inner join V_BarCode_Info b on b.barCode = t.barCode 
where outOrderCode='{planCode}' and operateType='03'";

                //order by barStatus desc
                dt = cmd.GetDataTable(sql);

               // var list = cmd.TableTolist<DbProductBarCode>(dt);
                var list =cmd.TableToDictionary(dt);
                rsl.Data = list;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Message = ex.Message;
            }
            return rsl;
        }

        /// <summary>
        /// 获取U8业务员信息
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public ReturnResult getPersonInfo(string jsonStr)
        {
            rsl = new ReturnResult();
            Dictionary<string, string> dic = new Dictionary<string, string>();
            Dictionary<string, object> listDic = new Dictionary<string, object>();
            List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
            #region 获取人员信息
            try
            {
                sb = new StringBuilder();
                if (string.IsNullOrWhiteSpace(jsonStr))
                {
                    rsl.Result = false;
                    rsl.Message = "参数不能为空";
                    return rsl;
                }
                //字符串解密
                jsonStr = Encryption.DesDecrypt(jsonStr);
                _log.Info("getPersonInfo：" + jsonStr);
                var json = JsonConvert.DeserializeObject<JObject>(jsonStr);
                var data = new List<Dictionary<string, string>>();

                if (json.Property("mobType") != null && !string.IsNullOrWhiteSpace(json["mobType"].ToString()) && json["mobType"].ToString().Equals("H5"))
                {
                    #region H5移动端方法
                    sb.Clear();
                    sb.Append("select cPersonCode userCode,cPersonName userName from Person  ");
                    
                    //var assistant = cmd.GetDataTable(sb.ToString());
                    var assistant = outBase.getData(sb.ToString(), json["baseCode"].ToString());
                    
                    if (assistant != null && assistant.Rows.Count > 0)
                    {
                        foreach (DataRow item in assistant.Rows)
                        {
                            var obj = new Dictionary<string, string>();
                            obj["value"] = item["userCode"].ToString();
                            obj["text"] = item["userName"].ToString() + "(" + item["userCode"].ToString() + ")";
                            data.Add(obj);
                        }
                    }
                    #endregion
                }
                rsl.Data = data;
                rsl.Result = true;
            }
            catch (Exception ex)
            {
                rsl.Result = false;
                rsl.Message = ex.Message;
                return rsl;
            }
            #endregion
            return rsl;
        }



    }
}

